<template>
  <div>
    <iframe v-if="!toOut" :id="id" :src="url" frameborder="0" width="100%" height="950px" scrolling="auto"></iframe>
    <a-card v-else :bordered="false">
      <a-alert message="当前已为您打开外部链接" type="success" show-icon
               style="margin-bottom: 10px">
        <div slot="description">
          请查看新打开的外部链接页面；若需重新打开，<a :href="outUrl" target="_blank" style="color: #0c8fcf">请点击此处</a>
        </div>
      </a-alert>
    </a-card>
  </div>

</template>

<script>
import Vue from 'vue'
import { ACCESS_TOKEN } from '@/store/mutation-types'
import PageLayout from '../page/PageLayout'
import RouteView from './RouteView'
import { USER_INFO } from '../../store/mutation-types'

export default {
  name: 'IframePageContent',
  inject: ['closeCurrent'],
  data() {
    return {
      url: '',
      id: '',
      toOut: false,
      outUrl: ''
    }
  },
  created() {
    this.goUrl()
  },
  updated() {
    this.goUrl()
  },
  watch: {
    $route(to, from) {
      this.goUrl()
    }
  },
  methods: {
    goUrl() {
      let url = this.$route.meta.url

      let id = this.$route.path
      this.id = id
      //url = "http://www.baidu.com"
      if (url !== null && url !== undefined) {
        if (url == 'http://192.168.9.67/eradmin/login_check.jsp?username=') {
          let params = Vue.ls.get(USER_INFO).avatar
          this.toOut = true
          this.outUrl = url + params
          //  打开新建页面
          window.open(this.outUrl)
        } else if (url == 'http://10.107.99.181/eaWorkValue/eaSum/workSum') {
          let params = Vue.ls.get(USER_INFO).realname
          this.toOut = false
          url = url + '?username=' + params
        } else {
          this.toOut = false
        }
        this.url = url
        /*update_begin author:wuxianquan date:20190908 for:判断打开方式，新窗口打开时this.$route.meta.internalOrExternal==true */
        if (this.$route.meta.internalOrExternal != undefined && this.$route.meta.internalOrExternal == true) {
          this.closeCurrent()
          //外部url加入token
          let tokenStr = '${token}'
          if (url.indexOf(tokenStr) != -1) {
            let token = Vue.ls.get(ACCESS_TOKEN)
            this.url = url.replace(tokenStr, token)
          }
          window.open(this.url)
        }
        /*update_end author:wuxianquan date:20190908 for:判断打开方式，新窗口打开时this.$route.meta.internalOrExternal==true */

      }
    }
  }
}
</script>

<style>
</style>